package com.panda.admin.login.access.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panda.admin.login.dto.RoleDto;
import com.panda.admin.login.dto.RoleMenuDto;
import com.panda.admin.login.entity.SystemRole;
import com.panda.admin.login.entity.SystemUserRole;
import com.panda.admin.login.access.service.SystemRoleService;
import com.panda.admin.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * author: tcy
 * createDate: 2023/5/11
 * description: 角色控制
 */
@Api(tags = "角色控制")
@RestController
@RequestMapping("/role")
public class SystemRoleController {

    @Autowired
    SystemRoleService systemRoleService;

    @ApiOperation(value = "查询全部角色")
    @GetMapping("/queryAll")
    public Result<List<SystemRole>> queryAll(){
        return Result.success(systemRoleService.queryAll());
    }

    @ApiOperation(value = "分页查询角色")
    @PostMapping("/queryRoles")
    public Result<Page<SystemRole>> queryRoles(@RequestBody RoleDto dto){
        return Result.success(systemRoleService.queryRoles(dto));
    }

    @ApiOperation(value = "查询角色详情")
    @GetMapping("/queryRoleById/{roleId}")
    public Result<SystemRole> queryRoleById(@PathVariable("roleId") Long roleId){
        return Result.success(systemRoleService.queryRoleById(roleId));
    }

    @ApiOperation(value = "根据用户id查角色")
    @GetMapping("/queryById/{userId}")
    public Result<SystemUserRole> queryById(@PathVariable("userId") Long userId){
        return Result.success(systemRoleService.queryById(userId));
    }

    @ApiOperation(value = "增改角色定位")
    @PostMapping("/saveOrUpdateRole")
    public Result<Boolean> saveOrUpdateRole(@RequestBody SystemRole systemRole){
        return Result.success(systemRoleService.saveOrUpdateRole(systemRole));
    }

    @ApiOperation(value = "删除角色")
    @PostMapping("/deleteRole")
    public Result<Boolean> deleteRole(@RequestBody List<Long> ids){
        return Result.success(systemRoleService.deleteRole(ids));
    }

    @ApiOperation(value = "角色配置菜单")
    @PostMapping("/configRoleMenu")
    public Result<Boolean> configRoleMenu(@RequestBody RoleMenuDto dto){
        return Result.success(systemRoleService.configRoleMenu(dto));
    }

    @ApiOperation(value = "更改角色权限排序")
    @GetMapping("/changeSort/{id}/{direction}")
    public Result<Boolean> changeSort(@PathVariable("id") Long id, @PathVariable("direction") String direction){
        return Result.success(systemRoleService.changeSort(id,direction));
    }
}
